from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
import time
testCase="DBshop004_取消订单流程"
# 1.在首页搜索"小米",点击搜索按钮
firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
# 搜索小米
firefox.find_element_by_xpath("//input[@name='keywords']").send_keys("小米")
# 点击搜索
firefox.find_element_by_xpath("//input[@class='search-btn iconfont']").click()
time.sleep(2)
# 2.选择小米mix3,加入到购物车,点击购物车按钮
firefox.find_element_by_link_text("小米Mix3 全网通版 8GB+128GB 黑色 磁动力滑盖全面屏").click()
firefox.switch_to.window(firefox.window_handles[-1])
firefox.find_element_by_id("add_cart_submit").click()
# 3.点击"去结算"按钮
firefox.find_element_by_link_text("去购物车结算").click()
firefox.find_element_by_link_text("去结算").click()
# 4.默认地址已经选择,点击下一步按钮
firefox.find_element_by_xpath("//input[@value='下一步']").click()
# 5.支付方式选择"余额支付",点击确认订单
firefox.find_element_by_xpath("//input[@value='yezf']").click()
firefox.find_element_by_xpath("//input[@value='确认订单']").click()
time.sleep(2)
# 获取订单编号给后续的查询订单使用
orderNo=firefox.find_element_by_xpath("(//font[@color='color:#ED145B'])[2]").text
# 获取项目的绝对路径
rootPath=get_pro_rootpath()
# 将订单编号写入到文件中,方面后面的脚本去使用这个订单编号
# 这就是跨脚本传递数据
writeFile(rootPath+'\public\order004.txt',orderNo)
# 6.点击"查看订单详情",点击"取消订单"
firefox.find_element_by_xpath("//input[@value='查看订单详情']").click()
firefox.find_element_by_xpath("//button[text()='取消订单']").click()
time.sleep(1)
firefox.switch_to.alert.accept()
time.sleep(1)
firefox.find_element_by_partial_link_text("无效订单").click()
firefox.find_element_by_xpath("//input[@name='search_order_sn']").send_keys(orderNo)
firefox.find_element_by_xpath("//button[text()='搜索']").click()
time.sleep(1)
# 断言
try :
    firefox.find_element_by_link_text(orderNo).is_displayed()
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败"%testCase)
    getPhoto(firefox)

firefox.quit()
